﻿using PlainConcepts.Fx.Dnie;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PlainConcepts.Fx.Dnie.SmartCard.Interop;
using System;
using System.IO;

namespace PlainConcepts.Fx.Dnie.Test
{
    
    
    /// <summary>
    ///This is a test class for DnieHelperTest and is intended
    ///to contain all DnieHelperTest Unit Tests
    ///</summary>
    [TestClass()]
    public class DnieHelperTest
    {

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        /// <summary>
        ///A test for SignDocument - XML
        ///</summary>
        [TestMethod()]
        [DeploymentItem(@"..\..\..\PlainConcepts.Fx.Dnie.Test\TestToSignXml.xml")]
        public void SignDocumentTest_SignXml()
        {
            DnieHelper target = new DnieHelper();
            string pathDocument =  Path.Combine(testContextInstance.TestDir, @"Out\PlainConcepts.Fx.Dnie.TestToSignXml.xml");
            string outputPath = Path.Combine(testContextInstance.TestDir, @"Out\PlainConcepts.Fx.Dnie.TestToSignXml.Output.xml");

            if (target.IsSmartCardPresent())
            {
                target.SignDocument(pathDocument, outputPath);
                Assert.IsTrue(File.Exists(outputPath));
            }
        }

        /// <summary>
        ///A test for SignDocument - WORD
        ///</summary>
        [TestMethod()]
        [DeploymentItem(@"..\..\..\PlainConcepts.Fx.Dnie.Test\TestToSignWord.docx")]
        [DeploymentItem(@"..\..\..\PlainConcepts.Fx.Dnie.Test\PlainConcepts.SmartCard.dll")]
        public void SignDocumentTest_SignWord()
        {
            DnieHelper target = new DnieHelper();
            string pathDocument = Path.Combine(testContextInstance.TestDir, @"Out\PlainConcepts.Fx.Dnie.TestToSignWord.docx");
            string outputPath = Path.Combine(testContextInstance.TestDir, @"Out\PlainConcepts.Fx.Dnie.TestToSignWord.Output.docx");

            if (target.IsSmartCardPresent())
            {
                target.SignDocument(pathDocument, outputPath);
                Assert.IsTrue(File.Exists(outputPath));
            }
        }

        /// <summary>
        ///A test for SignDocument - EXCEL
        ///</summary>
        [TestMethod()]
        [DeploymentItem(@"..\..\..\PlainConcepts.Fx.Dnie.Test\TestToSignExcel.xlsx")]
        [DeploymentItem(@"..\..\..\PlainConcepts.Fx.Dnie.Test\PlainConcepts.SmartCard.dll")]
        public void SignDocumentTest_SignExcel()
        {
            DnieHelper target = new DnieHelper();
            string pathDocument = Path.Combine(testContextInstance.TestDir, @"Out\PlainConcepts.Fx.Dnie.TestToSignExcel.xlsx");
            string outputPath = Path.Combine(testContextInstance.TestDir, @"Out\PlainConcepts.Fx.Dnie.TestToSignExcel.Output.xlsx");

            if (target.IsSmartCardPresent())
            {
                target.SignDocument(pathDocument, outputPath);
                Assert.IsTrue(File.Exists(outputPath));
            }
        }

        /// <summary>
        ///A test for IsSmartCardPresent
        ///</summary>
        [DeploymentItem(@"..\..\..\PlainConcepts.Fx.Dnie.Test\PlainConcepts.SmartCard.dll")]
        [TestMethod()]
        public void IsSmartCardPresentTest()
        {
            DnieHelper target = new DnieHelper();
            target.IsSmartCardPresent();
            
        }
    }
}
